Skip to content

Document that ASTHelpers.getSymbol(Tree) returns null for a parenthesized expression - #6297

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1013739787
Nov 4, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1013739787

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Document that ASTHelpers.getSymbol(Tree) returns null for a parenthesized expression

ASTHelpers.getSymbol((x)) returns null where getSymbol(x) returns the symbol of x, and the Javadoc did not say so. A caller that forgets stripParentheses gets no symbol for a parenthesized operand, including the expression of every synchronized statement, and usually treats that as "not a variable" without any error.

As discussed in #6223, the method keeps returning null: callers treat a non-null result as a sign that the tree itself is the identifier, member select, or invocation, and some cast it or pass it to getReceiver, which throws IllegalStateException when given a parenthesized expression. The Javadoc now states the null result and points at stripParentheses(Tree). A new test in ASTHelpersTest pins it, with that reason in its comment, so that a change making getSymbol look through parentheses fails it.

The old Javadoc also promised null when a compilation error left the symbol unresolved. Error Prone does not run checks on a compilation unit with errors, and an unresolved invocation, new expression, or member reference throws IllegalArgumentException from its typed overload instead of returning null. The comment now states what the code returns: null for an identifier or member select that javac left without a symbol. The inline comment in getSymbol names module names as one such case.

check_api/pom.xml lists ASTHelpersTest.java in testExcludes, so the GitHub Maven build does not compile or run the new test. I compiled and ran ASTHelpersTest by hand on JDK 25.0.4: all 67 tests pass. With a ParenthesizedTree case added at the top of getSymbol(Tree), the new test fails with expected: null / but was : x. javadoc -Xdoclint:all on ASTHelpers.java reports no errors; both {@link} targets resolve.

🤖 Generated with Claude Code

Fixes #6295

FUTURE_COPYBARA_INTEGRATE_REVIEW=#6295 from vlsi:claude/javadoc-getsymbol-improvement-ba25fb 4f5b241

…esized expression

`ASTHelpers.getSymbol((x))` returns null where `getSymbol(x)` returns the symbol of `x`, and the Javadoc did not say so. A caller that forgets `stripParentheses` gets no symbol for a parenthesized operand, including the expression of every `synchronized` statement, and usually treats that as "not a variable" without any error.

As discussed in #6223, the method keeps returning null: callers treat a non-null result as a sign that the tree itself is the identifier, member select, or invocation, and some cast it or pass it to `getReceiver`, which throws `IllegalStateException` when given a parenthesized expression. The Javadoc now states the null result and points at `stripParentheses(Tree)`. A new test in `ASTHelpersTest` pins it, with that reason in its comment, so that a change making `getSymbol` look through parentheses fails it.

The old Javadoc also promised null when a compilation error left the symbol unresolved. Error Prone does not run checks on a compilation unit with errors, and an unresolved invocation, `new` expression, or member reference throws `IllegalArgumentException` from its typed overload instead of returning null. The comment now states what the code returns: null for an identifier or member select that javac left without a symbol. The inline comment in `getSymbol` names module names as one such case.

`check_api/pom.xml` lists `ASTHelpersTest.java` in `testExcludes`, so the GitHub Maven build does not compile or run the new test. I compiled and ran `ASTHelpersTest` by hand on JDK 25.0.4: all 67 tests pass. With a `ParenthesizedTree` case added at the top of `getSymbol(Tree)`, the new test fails with `expected: null` / `but was : x`. `javadoc -Xdoclint:all` on `ASTHelpers.java` reports no errors; both `{@link}` targets resolve.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Fixes #6295

COPYBARA_INTEGRATE_REVIEW=#6295 from vlsi:claude/javadoc-getsymbol-improvement-ba25fb 4f5b241
PiperOrigin-RevId: 1013782394
@copybara-service
copybara-service Bot merged commit 161c201 into master Nov 4, 2026
2 checks passed
@copybara-service
copybara-service Bot deleted the test_1013739787 branch November 4, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant